package com.zt.rongda.salary.service;

import java.util.List;

import com.zt.rongda.salary.inter.SalaryPayRollQuotaMapper;
import com.zt.rongda.salary.model.SalaryPayRollQuota;
import com.zt.system.model.BusinessException;
import com.zt.servlet.ReqBean;
import com.zt.system.model.SqlBuilder;
import com.zt.system.service.BaseService;
import com.zt.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SalaryPayRollQuotaService extends BaseService {

    @Autowired
    private SalaryPayRollQuotaMapper salaryPayRollQuotaMapper;

    /**
    * 查询
    *
    * @param reqBean
    * @return
    */
    public JSONObject getTable(ReqBean reqBean) {
        SqlBuilder sqlBuilder = new SqlBuilder("");
        sqlBuilder.appendSql("select * from SALARY_PAYROLL_QUOTA where 1=1 ");
        return queryTable(sqlBuilder, reqBean.getPageSize(), reqBean.getPageIndex());
    }

    /**
    * 通过id查询
    *
    * @param id
    * @return
    */
    public SalaryPayRollQuota getById(String id) {
        return salaryPayRollQuotaMapper.selectByPrimaryKey(id);
    }

    /**
    * 新增
    *
    * @param salaryPayRollQuota
    */
    public void add(SalaryPayRollQuota salaryPayRollQuota) {
        salaryPayRollQuota.setId(stringId());// 手动设置Id

        salaryPayRollQuota.setMakeTime(new Date());
        salaryPayRollQuota.setModifyTime(salaryPayRollQuota.getMakeTime());
        salaryPayRollQuotaMapper.insert(salaryPayRollQuota);
    }

    /**
    * 修改
    *
    * @param salaryPayRollQuota
    */
    public void update(SalaryPayRollQuota salaryPayRollQuota) {
        String id = salaryPayRollQuota.getId();
        if (StringUtil.isEmpty(id)) {
            throw new BusinessException("获取主键失败");
        }

        salaryPayRollQuota.setModifyTime(new Date());
        salaryPayRollQuotaMapper.updateByPrimaryKeySelective(salaryPayRollQuota);
    }

    /**
    * 删除
    *
    * @param id
    */
    public void delete(String id) {
        if (StringUtil.isEmpty(id)) {
            throw new BusinessException("获取主键失败");
        }
        salaryPayRollQuotaMapper.deleteByPrimaryKey(id);
    }

}